﻿Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports DevExpress.XtraReports.UI

Public Class FormMain
    Dim objPgdMes As New clsPgdMes
    Dim objAutoNumber As New clsAutoNumber
    Dim objProdSpec As New clsProdSpec
    Dim objmstJP As New clsJPMst
    Private objYZZ As New clsProdInfo
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim _en As New entity_YZZ
    Dim objPgdMesWorkReport As New clsPgdMesWorkReport
    Dim objStorageLocationMst As New clsStorageLocationMst
    Dim httpHelper As New HttpHelper
    Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        connectDB()
        If String.IsNullOrEmpty(txtOper.Text) Then
            txtOper.Enabled = True
            btnChangeOper.Text = "保存"
        Else
            txtOper.Enabled = False
            btnChangeOper.Text = "切换用户"
        End If
        Dim startDate As String = Date.Now.ToShortDateString()
        DLStartDate.Text = startDate
        Dim endDate As String = Date.Now.ToShortDateString()
        DLEndDate.Text = endDate
        setDgvData()
        Dim _dt As DataTable = objmstJP.getJLList()
        If _dt.Rows.Count > 0 Then
            cmbJP_type.DisplayMember = "name"
            cmbJP_type.ValueMember = "model"
            cmbJP_type.DataSource = _dt
        End If
        AddHandler txtTZGBJL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        'AddHandler txtGQNCJL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        AddHandler txtBHJZL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        'AddHandler txtBBPZZL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        AddHandler txtJP_ZL.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        AddHandler lblGJBZL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        AddHandler txtgqbhjlL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
        AddHandler txtJSTZJL_SJ.TextChanged, AddressOf lblGJBZL_SJ_TextChanged
    End Sub

    Private Sub connectDB()
        g_szInitFileName = My.Application.Info.DirectoryPath & "\Client_YZZH.ini"

        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))
        txtOper.Text = GetIniFile("LOGIN", "user", "", g_szInitFileName)

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If

    End Sub

    Private Sub btnChangeOper_Click(sender As Object, e As EventArgs) Handles btnChangeOper.Click
        If btnChangeOper.Text.Equals("切换用户") Then
            txtOper.Enabled = True
            btnChangeOper.Text = "保存"
        Else
            If btnChangeOper.Text.Equals("保存") Then
                If String.IsNullOrEmpty(txtOper.Text.Trim()) = False Then
                    PutIniFile("LOGIN", "user", txtOper.Text.Trim(), g_szInitFileName)
                    txtOper.Enabled = False
                    btnChangeOper.Text = "切换用户"
                Else
                    MsgBox("请输入操作员账号")
                End If
            End If
        End If
    End Sub

    Private Sub lblQuit_Click(sender As Object, e As EventArgs) Handles lblQuit.Click
        PutIniFile("LOGIN", "user", "", g_szInitFileName)
        txtOper.Text = GetIniFile("LOGIN", "user", "", g_szInitFileName)
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        setDgvData()
    End Sub

    Private Sub setDgvData()
        Dim dt As DataTable = objPgdMes.getYzzPgd(0, DLStartDate.Text(), DLEndDate.Text, True)
        If dt.Rows.Count > 0 Then
            dt.Columns.Add("validity_name")
            For Each row As DataRow In dt.Rows
                If row("validity") = "0" Then
                    row("validity_name") = "无效"
                Else
                    row("validity_name") = "有效"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dt
    End Sub

    Private Sub btnMesPlan_Click(sender As Object, e As EventArgs) Handles btnMesPlan.Click
        'Dim params As String = "{""workshop"":""预组装"",""date"":""" & "2021-12-08" & """,""compid"":""0de02b54-4e55-4dbf-ab89-f785df5f405c""}"
        Dim params As String = "{""workshop"":""预组装"",""startdate"":""" & DateTime.Parse(DLStartDate.Text).ToString("yyyy-MM-dd") & """,""enddate"":""" & DateTime.Parse(DLEndDate.Text).ToString("yyyy-MM-dd") & """,""compid"":""0de02b54-4e55-4dbf-ab89-f785df5f405c""}"
        Dim rtn As String = httpHelper.HttpPostWebService("findDispatchOrderInfoListByTimeAndCJ", params)
        'MsgBox(rtn)
        Dim jo As JObject = JsonConvert.DeserializeObject(rtn)
        Dim code As String = jo("code").ToString() '输出0
        'MsgBox(code)
        Dim data As String = jo("data").ToString() '输出0
        'data = "[{""dispatchingorder"":""PGDH211103001"",
        '""start_time"":""2021-11-02 00:00:00"",
        '""end_time"":""2021-11-02 23:59:59"",
        '""project_code"":""fgm-test-0001"",
        '""project_name"":""fgm-test-0001"",
        '""equip_id"":""070046,070023,070020,070011,"",
        '""jp_type"":""mes不存在"",
        '""prod_spec_id"":""HDR-0.4-201-035-18"",""count"":9.0},
        '{""dispatchingorder"":""PGDH211103222"",""start_time"":""2021-11-02 00:00:00"",
        '""end_time"":""2021-11-02 23:59:59"",
        '""project_code"":""fgm-test-0001"",
        '""project_name"":""fgm-test-0001"",
        '""equip_id"":""070046,070023,070020,070011,"",
        '""jp_type"":""mes不存在"",
        '""prod_spec_id"":""HDR-0.4-201-035-18"",""count"":9.0}]"
        'MsgBox(data)
        Dim jarray As JArray = jarray.Parse(data)
        If jarray.Count > 0 Then
            For index = 0 To jarray.Count - 1
                Dim en As New entityPgdMes
                en.pgd_code = jarray(index)("dispatchingorder")
                en.oper_date = DateTime.Parse(jarray(index)("start_time")).ToShortDateString()
                en.start_time = jarray(index)("start_time").ToString()
                en.end_time = DateTime.Parse(jarray(index)("start_time")).AddDays(1).ToString()
                en.support_model = jarray(index)("p_prod_spec_id")
                en.type_value = jarray(index)("prod_spec_id")
                en.mes_project_code = jarray(index)("project_code")
                en.mes_project_name = jarray(index)("project_name")
                en.oper_count = jarray(index)("count")
                en.workshop_id = 0
                en.validity = "1"
                en.status = "1"
                en.origin = "0"
                en.Ope = txtOper.Text.Trim()
                en.jp_type = String.Empty
                en.note = String.Empty
                Dim dtmesdata As DataTable = objPgdMes.getListByPgd(jarray(index)("dispatchingorder").ToString())
                If dtmesdata.Rows.Count = 0 Then
                    Dim rtn_save As Integer = objPgdMes.insertxjORyzz(en)
                Else
                    Dim rtn_save As Integer = objPgdMes.updatexjORyzz(en)
                End If
            Next
        Else
            MsgBox("没有数据")
        End If
    End Sub

    Private Sub btnMesWorkReportList_Click(sender As Object, e As EventArgs) Handles btnMesWorkReportList.Click
        Dim formMesWorkReportList As New FormMesWorkReportList()
        formMesWorkReportList.ShowDialog(Me)
    End Sub

    Private Sub btnAssemblingRecord_Click(sender As Object, e As EventArgs) Handles btnAssemblingRecord.Click
        Dim formAssemblingRecord As New FormAssemblingRecord()
        formAssemblingRecord.ShowDialog(Me)
    End Sub

    Private Sub cmbJP_type_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbJP_type.SelectedIndexChanged
        'lblJPXH_SJ.Text = cmbJP_type.SelectedValue.ToString()
    End Sub

    Private Sub txtTZGBJL_SJ_MouseDown(sender As Object, e As MouseEventArgs) Handles txtTZGBJL_SJ.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = True
        UcDigitalKeyboard1.B_02 = True

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub

    Private Sub txtWeight_MouseDown(sender As Object, e As MouseEventArgs) Handles txtGQNCJL_SJ.MouseDown, txtBBPZZL_SJ.MouseDown, txtBHJZL_SJ.MouseDown, txtJP_ZL.MouseDown, txtJSTZJL_SJ.MouseDown, txtgqbhjlL_SJ.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = True
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub

    Public Sub jsWT()
        '目标装胶量
        lblSJZL.Text = CDbl(lblXJZZL.Text) + txtJSTZJL_SJ.Value + txtTZGBJL_SJ.Value
        'lblSJZL.Text = CDbl(lblJPZL.Text) + CDbl(lblGJBZL.Text) + CDbl(lblBHJZL.Text) + CDbl(txtJSTZJL_SJ.Text) + CDbl(txtTZGBJL_SJ.Text)
        'lblSJZL_2.Text = CDbl(lblGJBZL_SJ.Text) + CDbl(txtJP_ZL.Text) + CDbl(txtBBPZZL_SJ.Text) + CDbl(txtBHJZL_SJ.Text) + CDbl(txtTZGBJL_SJ.Text) - CDbl(txtGQNCJL_SJ.Text) - CDbl(txtgqbhjlL_SJ.Text) + CDbl(txtJSTZJL_SJ.Text)
        'lblSJZL_2.Text = CDbl(lblGJBZL_SJ.Text) + CDbl(txtJP_ZL.Text) + CDbl(txtBHJZL_SJ.Text)
        '实际装胶量
        lblSJZL_2.Text = CDbl(txtJP_ZL.Text) + CDbl(txtBHJZL_SJ.Text)

        lblXTZJL.Text = (CDbl(lblSJZL.Text) - CDbl(lblSJZL_2.Text)).ToString()

        lblTZNCJZL.Text = (CDbl(lblXTZJL.Text) - txtgqbhjlL_SJ.Value).ToString()

        If CDbl(lblTZNCJZL.Text) < 0 Then
            txtGQNCJL_SJ.Value = -(CDbl(lblTZNCJZL.Text))
            txtBBPZZL_SJ.Value = 0.00
        End If

        If CDbl(lblTZNCJZL.Text) > 0 Then
            txtBBPZZL_SJ.Value = CDbl(lblTZNCJZL.Text)
            txtGQNCJL_SJ.Value = 0.00
        End If

        If Math.Abs(CDbl(lblSJZL.Text) - CDbl(lblSJZL_2.Text)) <= CDbl(lbltotal_wt_error_range.Text) Then
            lblOKNG.Text = "OK"
        Else
            lblOKNG.Text = "NG"
        End If
    End Sub

    Private Sub lblGJBZL_SJ_TextChanged(sender As Object, e As EventArgs)
        If String.IsNullOrEmpty(lblGJBZL_SJ.Text.Trim()) = False Then
            jsWT()
        End If
    End Sub

    Private Sub txtDLNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtGJBDLNo.KeyDown
        Dim objGJBinfo As New clsGJBinfo
        If e.KeyCode = Keys.Enter Then
            'txtGJBDLNo.Text.Remove(txtGJBDLNo.Text.Length - 1)
            txtGJBDLNo.Text = txtGJBDLNo.Text.ToUpper()
            Dim dt As DataTable = objGJBinfo.getListByDlNo(txtGJBDLNo.Text.Trim())
            If dt.Rows.Count > 0 Then
                lblGJBPS_SJ.Text = dt.Rows(0)("layer_num")
                lblGJBZL_SJ.Text = dt.Rows(0)("wt")
                lblGJBXH_SJ.Text = dt.Rows(0)("gjb_type")
                lblgjb_sys_id.Text = dt.Rows(0)("sys_id")
                lblLabelNo.Text = dt.Rows(0)("label_no")
                lblLabelNo.Text = String.Format("{0}号标签", lblLabelNo.Text)
                txtTZGBJL_SJ.Text = FormatNumber((Decimal.Parse(lblGJBZL.Text) - Decimal.Parse(lblGJBZL_SJ.Text)) * 0.135, 3, vbTrue)
            Else
                lblGJBPS_SJ.Text = "0"
                lblGJBZL_SJ.Text = "0.0"
                lblGJBXH_SJ.Text = String.Empty
                lblgjb_sys_id.Text = String.Empty
                lblLabelNo.Text = String.Empty
            End If
            'objGJBinfo.setdefaultValue(txtGJBDLNo.Text, lblGJBPS_SJ, lblGJBZL_SJ, lblGJBXH_SJ, lblgjb_sys_id, lblLabelNo)
        End If
    End Sub

    Private Sub txtJP_Piece_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txtJP_Piece_num.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = False
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub

    Private Sub btnFinish_Click(sender As Object, e As EventArgs) Handles btnFinish.Click
        'mesbg(100, 1.ToString(), "02.02.1507", "nc接口测试")
        If check() Then
            Dim _EN As entity_YZZ = setEntity()
            If objYZZ.insert(_EN) <> -2 Then
                objAutoNumber.setNextKeyNo("prod_code", "prodAutoNumber")
                objAutoNumber.setNextKeyNo("gyh_code_" & objAutoNumber.getGYH_Header(), "gyhAutoNumber")
                objAutoNumber.setNextProjectValue(dgv.SelectedRows(0).Cells("mes_project_code").Value.ToString(), dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString())
                barcodePrint() '标签打印
                Dim b_SysId As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                Dim b_PgdMesProjectCode As String = dgv.SelectedRows(0).Cells("mes_project_code").Value.ToString()
                Dim b_PgdMes_gx As String = dgv.SelectedRows(0).Cells("Coltype_value").Value.ToString()
                Dim dtPgdMesWorkReport As DataTable = objPgdMesWorkReport.getListByPgdmesSysId("ok", b_SysId)
                If dtPgdMesWorkReport.Rows.Count > 0 Then
                    If MsgBox("确认进行合格报工吗？", vbYesNo, "提示") = vbYes Then
                        Dim mes_bg_rtn As Integer = objPgdMesWorkReport.insert("ok", b_SysId, 1.ToString(), txtOper.Text.Trim())
                        'mesbg(b_SysId, 1.ToString(), b_PgdMes_gx, b_PgdMesProjectCode)
                        If mes_bg_rtn <> -2 Then
                            MsgBox("保存成功，报工成功", vbYes, "提示")
                        Else
                            MsgBox("保存成功，报工失败", vbYes, "提示")
                        End If
                    End If
                Else
                    If MsgBox("确认要进行合格报工吗？", vbYesNo, "提示") = vbYes Then
                        Dim mes_bg_rtn As Integer = objPgdMesWorkReport.insert("ok", b_SysId, 1.ToString(), txtOper.Text.Trim())
                        'mesbg(b_SysId, 1.ToString(), b_PgdMes_gx, b_PgdMesProjectCode)
                        If mes_bg_rtn <> -2 Then
                            MsgBox("保存成功，报工成功", vbYes, "提示")
                        Else
                            MsgBox("保存成功，报工失败", vbYes, "提示")
                        End If
                    End If
                End If
                setDgvData()
                formClear()
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub
    Private Sub formClear()
        '法兰板
        txtFLBDLNo.Text = String.Empty
        lblFLBXH_SJ.Text = String.Empty
        lblwhich_side.Text = String.Empty
        lblflb_sys_id.Text = String.Empty
        lblflbNum.Text = "0"
        '骨架板
        txtGJBDLNo.Text = String.Empty
        lblGJBXH_SJ.Text = String.Empty
        lblGJBPS_SJ.Text = "0"
        lblGJBZL_SJ.Text = "0.0"
        lblgjb_sys_id.Text = String.Empty

        txtJP_Piece_num.Text = "0"
        txtJP_ZL.Text = "0.0"
        lblLabelNo.Text = ""
        '保护胶
        txtBHJZL_SJ.Text = "0.0"
        txtTZGBJL_SJ.Text = "0.0"
        txtBBPZZL_SJ.Text = "0.0"
        txtGQNCJL_SJ.Text = "0.0"
        '下侧
        lbltotal_wt_error_range.Text = "0"
        lblSJZL_2.Text = "0.0"
        lblOKNG.Text = String.Empty
    End Sub
    Private Function check() As Boolean
        Dim rtn As Boolean = True
        If txtOper.Text = "" Then
            MsgBox("操作员不能为空，请输入。")
            txtOper.Focus()
            Return False
        End If
        If dgv.SelectedRows.Count <= 0 Then
            MsgBox("请选择生产计划！")
            Return False
        End If
        If lblFLBXH.Text <> lblFLBXH_SJ.Text Then
            MsgBox("法兰板型号不符！")
            Return False
        End If
        If lblwhich_side.Text = "上层法兰板" Then
            MsgBox("请使用下层法兰板！")
            Return False
        End If
        If lblGJBXH.Text <> lblGJBXH_SJ.Text Then
            MsgBox("骨架板型号不符！")
            Return False
        End If
        If lblGJBPS.Text <> lblGJBPS_SJ.Text Then
            MsgBox("骨架板片数不符！")
            Return False
        End If
        If lblJLXH.Text <> lblJPXH_SJ.Text Then
            MsgBox("胶料型号不符！")
            Return False
        End If
        If lblJPPS.Text <> txtJP_Piece_num.Text Then
            MsgBox("胶片片数不符！")
            Return False
        End If
        'If String.IsNullOrEmpty(cmbLoc.Text) Then
        '    MsgBox("未获取到库位！")
        '    Return False
        'End If
        Try
            If txtJP_ZL.Text = "" OrElse CDbl(txtJP_ZL.Text) <= 0 Then
                MsgBox("请输入 胶片重量。")
                txtJP_ZL.Focus()
                Return False
            End If
        Catch ex As Exception
            MsgBox("胶片重量 输入错误。")
            txtJP_ZL.Focus()
            Return False
        End Try
        Try
            If txtBHJZL_SJ.Text = "" OrElse CDbl(txtBHJZL_SJ.Text) <= 0 Then
                MsgBox("请输入 保护胶重量。")
                txtBHJZL_SJ.Focus()
                Return False
            End If
        Catch ex As Exception
            MsgBox("保护胶重量 输入错误。")
            txtBHJZL_SJ.Focus()
            Return False
        End Try
        Return rtn
    End Function

    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        barcodePrint()
    End Sub

    Private Sub barcodePrint()
        Dim report As New XtraReport3()
        Dim printTool As New ReportPrintTool(report)
        If dgv.SelectedRows.Count > 0 Then
            report.Xr_lbl_support_model.Text = _en.spec_name
            report.Xr_lbl_project_name.Text = dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString()
            report.Xr_lbl_project_code.Text = _en.project_no 'dtxxx.Rows(0)("mes_project_code") '项目编号
            report.Xr_lbl_yzz_DateTime.Text = Now.ToString 'dtx.Rows(0)("org_time") '预组装时间
            report.XrBarCode1.Text = _en.prod_id 'lblprodid.Text.Trim() '生产编号
            report.Xr_lbl_jp_type.Text = _en.jp_type 'lblJLXH.Text.Trim() '胶料类型     
            report.Xr_lbl_gyh.Text = _en.steel_seal_no ' dtx.Rows(0)("steel_seal_no") '钢印号
            report.Xr_lbl_location.Text = _en.location '库位编号
            printTool.Print()
        End If
    End Sub

    Private Sub txtFLBDLNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtFLBDLNo.KeyDown
        Dim objFLBinfo As New clsFLBinfo
        If e.KeyCode = Keys.Enter Then
            txtFLBDLNo.Text = txtFLBDLNo.Text.ToUpper()
            'Dim txt_flb_dl_no As String = txtFLBDLNo.Text.ToUpper().Substring(0, txtFLBDLNo.Text.Trim().Length - 1)
            Dim dt As DataTable = objFLBinfo.selectALlByDL(txtFLBDLNo.Text)
            If dt.Rows.Count > 0 Then
                lblFLBXH_SJ.Text = dt.Rows(0)("flb_type")
                lblwhich_side.Text = IIf(dt.Rows(0)("which_side") = 0, "下层法兰板", "上层法兰板")
                lblflb_sys_id.Text = dt.Rows(0)("sys_id")
                lblflbNum.Text = CInt(dt.Rows(0)("piece_num")) - CInt(dt.Rows(0)("used_piece_num"))
            Else
                lblFLBXH_SJ.Text = String.Empty
                lblwhich_side.Text = String.Empty
                lblflb_sys_id.Text = String.Empty
                lblflbNum.Text = String.Empty
            End If
        End If
    End Sub

    Public Function setEntity() As entity_YZZ
        Dim prod_id As String = Now.ToString("yyyyMMdd") & "-" & objAutoNumber.getNextKeyNo("prod_code", "prodAutoNumber") '生产编号
        Dim gyhno As Integer = objAutoNumber.getNextKeyNo("gyh_code_" & objAutoNumber.getGYH_Header(), "gyhAutoNumber")
        Dim steel_seal_no As String = objAutoNumber.getGYH_Header() & String.Format("{0:D6}", gyhno)  '钢印号
        Dim project_no As Integer = objAutoNumber.getNextProjectNo(dgv.SelectedRows(0).Cells("mes_project_code").Value.ToString(), dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString())
        Dim project_noo As String = String.Format("{0:D4}", project_no) '项目编号
        With _en
            .factory_id = "TS"
            .prod_id = prod_id
            .gjb_sys_id = lblgjb_sys_id.Text
            .gjb_dl_no = txtGJBDLNo.Text
            .flb_sys_id = lblflb_sys_id.Text
            .flb_dl_no = txtFLBDLNo.Text
            .jp1wt = CDbl(lblJPZL.Text)
            .tzgb_wt = CDbl(txtTZGBJL_SJ.Text)
            .bbp_wt = CDbl(txtBBPZZL_SJ.Text)
            .gqncj_wt = CDbl(txtGQNCJL_SJ.Text)
            .bhj_wt = CDbl(txtBHJZL_SJ.Text)
            .status = "2"
            .set_bhj_ope = txtOper.Text.Trim()
            .update_time = Now()
            .prod_spec_id = dgv.SelectedRows(0).Cells("support_model").Value.ToString()
            .jp_type = cmbJP_type.Text
            .steel_seal_no = steel_seal_no
            .flbnum = CInt(lblflbNum.Text)
            .spec_name = dgv.SelectedRows(0).Cells("Colprod_spec_name").Value.ToString()
            .gqbhj_wt = CDbl(txtgqbhjlL_SJ.Text)
            .jstz_wt = CDbl(txtJSTZJL_SJ.Text)
            .project_no = project_noo
            .b_pgd_yzz_details_sys_id = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
            .rv_ope = txtOper.Text.Trim()
            .location = cmbLoc.Text
        End With
        Return _en
    End Function

    Private Function mesbg(PgdMesSysId As String, oper_num As String, productorname As String, b_gtPgdMesProjectCode As String) As Integer
        Dim rtn_int As Integer = -2
        Dim params As String = "{"
        params &= """project_code"":""" & b_gtPgdMesProjectCode & """," 'mes合批号
        params &= """qualifiednumber"":""" & Double.Parse(oper_num) & """," '报工的合格数
        params &= """unqualifiednumber"":""" & 0.00 & """," '报工的不合格数
        params &= """productorname"":""" & productorname & """," '报工产品编码
        params &= """procedurename"":""" & "预组装" & """," '报工工序
        params &= """compid"":""0de02b54-4e55-4dbf-ab89-f785df5f405c""," '公司id
        params &= """unqualifiedReason"":""" & "" & """" '不合格原因
        params &= "}"
        Dim rtn As String = httpHelper.HttpPostWebService("dispatchingOrderBG", params)
        Dim jo As JObject = JsonConvert.DeserializeObject(rtn)
        Dim code As String = jo("code").ToString() '输出0
        Dim msg As String = jo("msg").ToString() '输出操作成功
        If code.Equals("0") And msg.Equals("操作成功") Then
            rtn_int = objPgdMesWorkReport.insert("ok", PgdMesSysId, oper_num, txtOper.Text.Trim())
        End If
        Return rtn_int
    End Function

    Private Sub FormMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        DBacs.Disconnect()
    End Sub

    Private Sub btnPrintTest_Click(sender As Object, e As EventArgs) Handles btnPrintTest.Click
        Dim report As New XtraReport3()
        Dim printTool As New ReportPrintTool(report)
        report.Xr_lbl_support_model.Text = "ddsdsds"
        report.Xr_lbl_project_name.Text = "测试项目名称"
        report.Xr_lbl_project_code.Text = "项目编号" 'dtxxx.Rows(0)("mes_project_code") '项目编号
        report.Xr_lbl_yzz_DateTime.Text = Now.ToString() 'dtx.Rows(0)("org_time") '预组装时间
        report.XrBarCode1.Text = "sdssdsdddd" 'lblprodid.Text.Trim() '生产编号
        report.Xr_lbl_jp_type.Text = "xl-0.3" 'lblJLXH.Text.Trim() '胶料类型     
        report.Xr_lbl_gyh.Text = "GYH001" ' dtx.Rows(0)("steel_seal_no") '钢印号
        printTool.Print()
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            Dim _dt As DataTable = objProdSpec.selectAllbySpecId(dgv.SelectedRows(0).Cells("support_model").Value.ToString())
            If _dt.Rows.Count > 0 Then
                Me.lblBHJXH.Text = _dt.Rows(0)("bhj_jp_type")
                Me.lblJLXH.Text = _dt.Rows(0)("jp_type")
                Me.lblGJBXH.Text = _dt.Rows(0)("gjb_type")
                Me.lblJPZL.Text = _dt.Rows(0)("rubber_layer_thickness_total")
                Me.lblGJBZL.Text = _dt.Rows(0)("gjb_st_wt")
                Me.lblBHJZL.Text = _dt.Rows(0)("bhj_st_wt")
                Me.lblJPPS.Text = _dt.Rows(0)("jp_layer_num")
                Me.lblGJBPS.Text = _dt.Rows(0)("gjb_layer_num")
                Me.lblFLBXH.Text = _dt.Rows(0)("flb_type")
                Me.lblXJZZL.Text = _dt.Rows(0)("xj_wt_total")
                lblJPXH_SJ.Text = lblJLXH.Text
                'lblSJZL.Text = CDbl(_dt.Rows(0)("rubber_layer_thickness_total")) + CDbl(_dt.Rows(0)("gjb_st_wt")) + CDbl(_dt.Rows(0)("bhj_st_wt")) + CDbl(txtJSTZJL_SJ.Text) + CDbl(txtTZGBJL_SJ.Text)
                lbltotal_wt_error_range.Text = CDbl(_dt.Rows(0)("total_wt_error_range"))

                If lblGJBXH.Text.Contains("500") Or lblGJBXH.Text.Contains("600") Then
                    setLoc("A2", "A1")
                ElseIf lblGJBXH.Text.Contains("700") Or lblGJBXH.Text.Contains("800") Then
                    setLoc("A4", "A3")
                ElseIf lblGJBXH.Text.Contains("900") Or lblGJBXH.Text.Contains("1000") Then
                    setLoc("A6", "A5")
                End If
            End If
        End If
    End Sub

    Private Sub setLoc(l_Ax As String, l_Ay As String)
        Dim dtSLM As DataTable = objStorageLocationMst.getAvailableList("yzzck", l_Ax, l_Ay)
        cmbLoc.Items.Clear()
        If dtSLM.Rows.Count > 0 Then
            For index = 0 To dtSLM.Rows.Count - 1
                cmbLoc.Items.Add(dtSLM.Rows(index)("location_no"))
            Next
            cmbLoc.SelectedIndex = 0
        End If
    End Sub

    Private Sub txtTZGBJL_SJ_TextChanged(sender As Object, e As EventArgs) Handles txtTZGBJL_SJ.TextChanged
        'If txtTZGBJL_SJ.Value < 0 Then
        '    txtGQNCJL_SJ.Enabled = True
        '    txtBBPZZL_SJ.Enabled = False
        'End If

        'If txtTZGBJL_SJ.Value > 0 Then
        '    txtBBPZZL_SJ.Enabled = True
        '    txtGQNCJL_SJ.Enabled = False
        'End If

    End Sub

    Private Sub txtBHJZL_SJ_TextChanged(sender As Object, e As EventArgs) Handles txtBHJZL_SJ.TextChanged
        txtgqbhjlL_SJ.Value = txtBHJZL_SJ.Value - Decimal.Parse(lblBHJZL.Text)
    End Sub
End Class

'Public Class entityPgdMes
'    Public pgd_code As String
'    Public oper_date As String
'    Public mes_project_code As String
'    Public mes_project_name As String
'    Public support_model As String
'    Public type_value As String
'    Public oper_count As String
'    Public lhj As String
'    Public lhj_type As String
'    Public note As String
'    Public workshop_id As Integer
'    Public validity As String
'    Public status As String
'    Public origin As String
'    Public Ope As String
'    Public start_time As String
'    Public end_time As String
'    Public jp_type As String
'    Public jp_spec As String

'End Class


Public Class entity_YZZ
    Public factory_id As String
    Public prod_id As String
    Public gjb_sys_id As String
    Public gjb_dl_no As String
    Public flb_sys_id As String
    Public flb_dl_no As String
    Public jp1wt As Double
    Public tzgb_wt As Double
    Public bbp_wt As Double
    Public gqncj_wt As Double
    Public bhj_wt As Double
    Public status As String
    Public set_bhj_ope As String
    Public update_time As String
    Public prod_spec_id As String
    Public jp_type As String
    Public steel_seal_no As String
    Public flbnum As Integer
    Public spec_name As String
    Public gqbhj_wt As Double
    Public jstz_wt As Double
    Public project_no As String
    Public b_pgd_yzz_details_sys_id As String
    Public rv_ope As String
    Public location As String
End Class

